package chatClient.view;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.regex.*;
/**
 * The purpose of this class is displayed the help file containing the instructions on how to use the software
* @author Tung Nguyen, Trung V Hoang, Rob Bernard, Justin Semmel
* @see java.util.Observable
* @since September 2012 
* @see ObserverChat, ObservableChat
**/
public class displayHelp extends JFrame {
/*  'displayHelp.java'  created by: Team N3 for Swinburne Uni HET715s2/Dr. Recep Ulusoy, 2/10/2012 v0.0 (final)
*   ===========================================================================
*
*   A simple Class program set that provides a User display of program operating instructions in response to clicking 
*   the GUI Client 'Help' button.  The button handler then passes control to this code.
*   
*   	Java Code Writer:  		Trung Hoang      
*	Embedded documentation:              Rob Bernard
*	JavaDoc development:		Justin Semmel
*
*
*  CONTENTS:
*
*	1.   Setup GUI Help Display
*	2.   Read Help File & transfer text to Help Box              
*
*
*  CLASSES CALLED:  Container, GridBagConstraints, DataInputStream, FileInputStream, BufferedReader, 
*  ==============    InputStreamReader, JTextArea
*/
    
    private JTextArea content = new JTextArea(32,15);
    private String dir = "helpContent.txt"; // get path of source folder
    
    public displayHelp()
    {
        setSize(460,580);					// Help Box size
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setTitle(" Help Content: ");				// Help box title

        Container container = this.getContentPane();		// Format container for display:
        container.setLayout(new GridBagLayout());      
        GridBagConstraints c = new GridBagConstraints();        
        c.fill = GridBagConstraints.HORIZONTAL;
        c.weightx = 0.01;      
        c.gridx = 0;
        c.gridy = 0;
        c.anchor = GridBagConstraints.CENTER;
        content.setForeground(Color.blue);
        content.setEditable(false);
        content.setLineWrap(true);
        content.setWrapStyleWord(true);
        container.add(new JScrollPane(content),c);		// Auto-Scrollbar
        
/*
*   ***  2.   Read Help File & transfer text to Help Box  ***
*	( Open the text help file specified in 'dir' and place the contents into the Help window)
*/       
        try{
	        // Open the file that is the first 
	        // command line parameter
			// Read Help file (of name given in 'dir')
	        FileInputStream fstream = new FileInputStream(dir); 
	        // Get the object of DataInputStream
	        DataInputStream in = new DataInputStream(fstream);
	        BufferedReader br = new BufferedReader(new InputStreamReader(in));
	        String allContent = "";	// Clear text buffer
	        String strLine;
	        //Read File Line By Line
	        while ((strLine = br.readLine()) != null)   {
	        // Print the content on the console

	        allContent += strLine + "\n\r";

	        }
	        content.setText(allContent); // Print the contents in the box
	        //Close the input stream
	        in.close();
	            }catch (Exception e){//Catch exception if any
	        System.err.println("Error: " + e.getMessage());
        }        
    }
}
